class Player < ActiveRecord::Base
	def pairs
		pairs ||= Pair.where("p1_id = ? OR p2_id = ?", id, id)
	end
	def games
		games ||= pairs.collect{|a| a.game}
	end	
	def score
		pairs.collect{|p| p.score.nil? ? 0 : p.score}.sum
	end
	def has_not_played (id)
		 pairs.select{|a| a.p1_id == id || a.p2_id == id}.empty?
	end
	def games_played
		pairs.select{|a| a.played}.count
	end
end
